<template>
  <div class="careerTools">
    <div class="careerToolsTitle">求职工具</div>
    <div class="careerToolsList">
      <el-tooltip
        v-for="(item, index) in careerToolsList"
        :key="index"
        placement="left"
        effect="light"
        popper-class="careerToolsItemPopper"
      >
        <div slot="content">
          <img :src="item.qrCodeUrl" alt="" srcset="" />
          <p>扫码体验{{ item.title }}服务</p>
        </div>
        <div class="careerToolsItem">
          <div class="careerToolsItemTitle">
            {{ item.title }}
            <img
              :src="careerToolsRightArrow"
              alt=""
              class="careerToolsRightArrow"
            />
          </div>
          <div class="careerToolsItemDesc">
            {{ item.desc }}
          </div>
        </div>
      </el-tooltip>
    </div>
  </div>
</template>

<script>
import careerToolsRightArrow from '@/assets/home/careerToolsRightArrow.png';
import { createQROther, getShareQrRights } from '@/api/home';
export default {
  name: 'careerTools', //已废弃，不用管
  data() {
    return {
      careerToolsList: [
        {
          rightId: 1,
          title: '性格测评',
          desc: '了解自己的行为表现，适应不同环境',
          qrCodeUrl: '',
          valid: false //权限判断,
        },
        // {
        //   rightId: 2,
        //   title: '职业测评',
        //   desc: '找到最符合自己的性格类型的职业',
        //   qrCodeUrl: '',
        //   valid: false //权限判断,
        // },
        {
          rightId: 4,
          title: 'AI简历诊断',
          desc: '定位简历问题,分析优劣势,提供建议',
          qrCodeUrl: '',
          valid: false //权限判断,
        },
        {
          rightId: 17,
          title: 'AI面评',
          desc: '线上模拟面试,专业题库,专业评估',
          qrCodeUrl: '',
          valid: false //权限判断,
        }
      ],
      careerToolsRightArrow
    };
  },
  mounted() {
    this.getShareQrRightsFn(); //配置权限
    this.careerToolsList.forEach((item) => {
      setTimeout(async () => {
        await this.createQROtherFn(item);
      }, 1500);
    });
  },
  methods: {
    // 创建二维码
    async createQROtherFn(careerToolsItem) {
      const cardType = localStorage.getItem('cardType')
        ? localStorage.getItem('cardType')
        : '28';
      const params = {
        path: 'pagesSub/careerGrow/dataCenterParse/index',
        scene: `ct=${cardType}&rightId=${
          careerToolsItem.rightId
        }&force=1&role=${localStorage.getItem('roleType')}`
      };
      const res = await createQROther(params);
      if (res.code == 200) {
        careerToolsItem.qrCodeUrl = res.data;
      }
    }
  },
  async getShareQrRightsFn() {
    const res = await getShareQrRights();
    if (res.code == 200) {
      console.log('------------------>getShareQrRights', res.data);
      //给每个工具添加权限返回的res.data里包含跟工具对应的权限信息rightId，将valid赋值为true
      this.careerToolsList.forEach((item) => {
        const right = res.data.find((r) => r.rightId === item.rightId);
        if (right) {
          item.valid = true;
        }
      });
      console.log(
        '------------------>this.careerToolsList',
        this.careerToolsList
      );
    }
  }
};
</script>

<style lang="scss" scoped>
.careerTools {
  display: flex;
  flex-direction: column;
  // height: 254px;
  .careerToolsTitle {
    color: #100f0f;
    font-size: 16px;
    font-weight: 800;
    line-height: 22px;
    height: 20px;
    display: flex;
    align-items: center;
    margin-bottom: 24px;
  }
  .careerToolsList {
    .careerToolsItem {
      margin-bottom: 24px;
      &:last-of-type {
        margin-bottom: 0px;
      }
      cursor: pointer;
      .careerToolsItemTitle {
        display: flex;
        justify-content: space-between;
        align-items: center;
        font-family: PingFangSC, PingFang SC;
        font-weight: 400;
        font-size: 14px;
        color: #222222;
        line-height: 18px;
        text-align: left;
        font-style: normal;
        margin-bottom: 9px;
        .careerToolsRightArrow {
          width: 16px;
          height: 16px;
        }
      }
      .careerToolsItemDesc {
        // max-width: 171px;
        font-family: PingFangSC, PingFang SC;
        font-weight: 400;
        font-size: 12px;
        color: #a2a5b3;
        line-height: 18px;
        text-align: left;
        font-style: normal;
        text-align: left;
        font-style: normal;
        text-overflow: ellipsis;
        overflow: hidden;
        // white-space: nowrap;
      }
    }
  }
}
</style>
